<?php
namespace Admin\Controller;
class LommodityController extends BaseController {
    public function index(){
        //商品管理
        $Lommodity =  M('pro');
        $data = I('post.');
        $offset = ($data['page'] - 1) * $data['rows'];
        $count = $Lommodity->count(); //数据总记录数
        $Page =  new \Think\Page($count,5);//每页显示多少条
        $rs = $Lommodity->join("imooc_cate ON imooc_pro.cid = imooc_cate.id")
                                    ->limit($Page->firstRow.','.$Page->listRows)
                                    ->field("imooc_pro.*,imooc_cate.cName")
                                    ->select();
        $show = $Page->show();// 分页显示输出
        $this->assign('page',$show);// 赋值分页输出
        $this->assign('Rs',$rs);
        $this->display();
    }
    public function Img(){
        $data = I('get.');
        $Img = M('pro');
        $rs = $Img->where($data)->field('pImg')->select();
        //dump($rs);
        $this->assign('Img',$rs);
        $this->display();
    }
    public function Dell(){
        $Lommodity =  M('pro');
        $data = I('post.');
        $rs = $Lommodity->delete($data['id']);
        if(!empty($rs)){
            $array = array('status'=>"1",'info'=>"删除成功",'url'=>U('Lommodity/index'));
        }else{
            $array = array('status'=>"0",'info'=>"删除失败",'url'=>U('Lommodity/index'));
        }
        $this->ajaxReturn($array);
    }
    public function xiugai(){
        $Lommodity =  M('pro');
        $data = I('get.');
        $rs = $Lommodity->where($data)->select();
        if (!empty($rs)){
            $this->assign('rs',$rs);
        }
        $this->display();
    }
    public function doXiugai(){
        $Lommodity =  M('pro');
        $data = I('post.');
        $rs = $Lommodity->save($data);
        if(!empty($rs)){
            $array = array('status'=>"1",'info'=>"修改成功",'url'=>U('Lommodity/index'));
        }else{
            $array = array('status'=>"0",'info'=>"修改失败",'url'=>U('Lommodity/index'));
        }
        $this->ajaxReturn($array);
    }
}
